# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/3/13 11:37

from selenium.webdriver.common.by import By
from datetime import datetime,timedelta

class  AdminDataStorageLocator:

    # 等待转圈 [class="antd4-spin-dot antd4-spin-dot-spin"]
    wait = (By.CSS_SELECTOR, '[class="antd4-spin-dot antd4-spin-dot-spin"]')

    """
        Data Storage Subscription | Subscription History
    """
    # data_storage_subscription菜单
    data_storage_subscription_menu = (By.XPATH,'//div[contains(@data-menu-id,"DATA_STORAGE_SUBSCRIPTION_PLT")]/span')
    # DATA_STORAGE_SUBSCRIPTION菜单是否打开  class="antd4-menu antd4-menu-sub antd4-menu-inline" 即为打开
    if_open_data_storage_subscription = (By.XPATH,'//div[contains(@data-menu-id,"DATA_STORAGE_SUBSCRIPTION_PLT")]/../ul')
    # Subscription History菜单
    subscription_history_menu = (By.XPATH, '//div[text()="Subscription History" and @class="cre-menu-layer-2"]')
    # subscription_history 页面文本，确认进入页面
    subscription_history_page_text = (By.XPATH, '(//*[text()="Subscription History"])[2]')
    # 查询条件选择
    click_input_type = (By.XPATH,'//input[@id="inputType"]/..')
    # 根据文本定位等待选择的元素, id(email,fileSubscribeName)
    def choose_by_name(text_name,id):
        context1 = '//div[text()="'+text_name+'"]/..'
        context2 = '[id="' + id + '"]'
        return (By.XPATH,context1),(By.CSS_SELECTOR,context2)
    # 获取列表第一行数据值: 2 Operator Email ,3 Subscription Name
    def get_list_first(id):
        context = '((//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]//div[@class="cre-table-nowrap"])['+id+']'
        return (By.XPATH,context)
    # 获取列表第一行时间值
    get_first_time = (By.XPATH,'(//tr[@class="antd4-table-row antd4-table-row-level-0"])[1]/td[1]')
    # search按钮
    click_search = (By.XPATH,'//span[text()="Search"]/..')
    # email_list列表
    email_list = (By.XPATH,'//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[4]/div')
    # Subscription Name 列表
    subscription_name_list = (By.XPATH,'//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[5]/div')
    # 时间框选项清除按钮
    clear_time = (By.XPATH, '//*[@fill-rule="evenodd"]/..')
    # 时间选择框
    # class="antd4-picker-input antd4-picker-input-active"
    order_time = (By.CSS_SELECTOR, '[class="antd4-picker-input antd4-picker-input-active"]')
    # # 选择开始时间title="2023-12-25"
    # now = datetime.now()
    # one_day_ago = now - timedelta(days=1)
    # now_str = now.strftime('%Y-%m-%d')
    # now_str1 = now.strftime('%m-%d-%Y')
    # content = '[title="' + now_str + '"]'
    # order_select_time = (By.CSS_SELECTOR, content)
    #
    # now_str_yes = one_day_ago.strftime('%Y-%m-%d')
    # content_yes = '[title="' + now_str_yes + '"]'
    # order_select_time_yesterday = (By.CSS_SELECTOR, content_yes)
    # 选择特定时间，2023-01-02
    def select_time(str):
        time = '[title="' + str + '"]'
        return (By.CSS_SELECTOR, time)
    # 时间选择框向前选择
    choose_time_before = (By.XPATH, '(//button[@class="antd4-picker-header-prev-btn"])[1]')
    # 页面total总是
    total_text = (By.CSS_SELECTOR, '[class="antd4-pagination-total-text"]')
    # 数据列时间数据项
    time_list = (By.XPATH,'//tr[@class="antd4-table-row antd4-table-row-level-0"]/td[1]')
